package com.woyou.ui.adapter;

import java.util.List;
import android.annotation.SuppressLint;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
import com.citaq.ideliver.R;
import com.woyou.utils.LogUtil;

public class DetailsAdapter extends BaseAdapter {
	
	private static final String TAG = "DetailsAdapter";
	
	private List<String> optionList;
	private LayoutInflater layoutInflater;

	public DetailsAdapter(Context context, List<String> optionList) {
		layoutInflater = LayoutInflater.from(context);
		this.optionList = optionList;
	}
	
	public void setOptionList(List<String> optionList){
		this.optionList = optionList;
	}

	@Override
	public int getCount() {
		return optionList.size();
	}

	@Override
	public Object getItem(int position) {
		return position;
	}

	@Override
	public long getItemId(int position) {
		return position;
	}
	
	int count = 0;
	
	@SuppressLint("InflateParams")
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		LogUtil.d(TAG, "position=" + position + "  count=" + count);
		count++;
		ViewHolder viewHolder = null;
		if (convertView == null) {
			convertView = layoutInflater.inflate(R.layout.item_details_lv, null);
			viewHolder = new ViewHolder();
			viewHolder.name = (TextView) convertView.findViewById(R.id.item_details_name);
			convertView.setTag(viewHolder);
		} else {
			viewHolder = (ViewHolder) convertView.getTag();
		}
		viewHolder.name.setText("" + optionList.get(position));
		return convertView;
	}

	static class ViewHolder {
		TextView name;
	}
	
	@Override
	public void notifyDataSetChanged() {
		count = 0;
		super.notifyDataSetChanged();
	}
	
}
